home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Text⁄Files / Voyeur 1.1.1 / Voyeur ƒ / v code ƒ / v window maintenance.c < prev    next >
Text File  |  1994-02-26  |  4KB  |  150 lines

  1. /**********************************************************************\
  2.  
  3. File:        v window maintenance.c
  4.  
  5. Purpose:    This module handles program windows -- opening, closing,
  6.             and otherwise keeping track of.
  7.  
  8.  
  9. Voyeur -- a no-frills file viewer
  10. Copyright ©1993-4, Mark Pilgrim
  11.  
  12. This program is free software; you can redistribute it and/or modify
  13. it under the terms of the GNU General Public License as published by
  14. the Free Software Foundation; either version 2 of the License, or
  15. (at your option) any later version.
  16.  
  17. This program is distributed in the hope that it will be useful,
  18. but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  20. GNU General Public License for more details.
  21.  
  22. You should have received a copy of the GNU General Public License
  23. along with this program in a file named "GNU General Public License".
  24. If not, write to the Free Software Foundation, 675 Mass Ave,
  25. Cambridge, MA 02139, USA.
  26.  
  27. \**********************************************************************/
  28.  
  29. #include "program globals.h"
  30. #include "v window maintenance.h"
  31. #include "msg graphics.h"
  32. #include "msg menus.h"
  33. #include "msg environment.h"
  34. #include "util.h"
  35.  
  36. Boolean IsProgramWindow(WindowPtr theWindow)
  37. {
  38.     return (GetProgramWindowIndex(theWindow)!=-1);
  39. }
  40.  
  41. void CloseProgramWindow(int index)
  42. {
  43.     int                i;
  44.     
  45.     FSClose(gTheRefNum[index]);
  46.     CloseTheWindow(kMainWindow+index);
  47.     for (i=index; i<CountProgramWindows()-1; i++)
  48.         MoveProgramWindow(i+1, i);
  49.     gTheWindow[kMainWindow+CountProgramWindows()-1]=0L;
  50.     gInitedWindowBounds[kMainWindow+CountProgramWindows()-1]=FALSE;
  51.     gOffscreenNeedsUpdate[kMainWindow+CountProgramWindows()-1]=TRUE;
  52.     BuildProgramWindowMenu();
  53. }
  54.  
  55. void OpenProgramWindow(int index)
  56. {
  57.     Mymemcpy(gWindowTitle[kMainWindow+index], gTheFS[index].name, gTheFS[index].name[0]+1);
  58.     OpenTheWindow(kMainWindow+index);
  59.     ObscureCursor();
  60.     gNeedOpenDialog=FALSE;
  61.     BuildProgramWindowMenu();
  62. }
  63.  
  64. void UpdateProgramWindow(int index, Boolean changed)
  65. {
  66.     if (changed)
  67.         gOffscreenNeedsUpdate[kMainWindow+index]=TRUE;
  68.     UpdateTheWindow(kMainWindow+index);
  69. }
  70.  
  71. void SelectProgramWindow(WindowPtr theWindow)
  72. {
  73.     SelectWindow(theWindow);
  74.     AdjustMenus();
  75. }
  76.  
  77. WindowPtr GetProgramWindowFromIndex(int index)
  78. {
  79.     return gTheWindow[kMainWindow+index];
  80. }
  81.  
  82. int GetProgramWindowIndex(WindowPtr theWindow)
  83. {
  84.     int                i;
  85.     
  86.     if (theWindow==0L) return -1;
  87.     
  88.     for (i=0; i<MAX_WINDOWS; i++)
  89.         if (theWindow==gTheWindow[kMainWindow+i])
  90.             return i;
  91.     
  92.     return -1;
  93. }
  94.  
  95. int CountProgramWindows(void)
  96. {
  97.     if (gWindowMenu!=0L) return CountMItems(gWindowMenu);
  98.     else return 0;
  99. }
  100.  
  101. void MoveProgramWindow(int oldIndex, int newIndex)
  102. {
  103.     gTheFS[newIndex]=gTheFS[oldIndex];
  104.     gTheRefNum[newIndex]=gTheRefNum[oldIndex];
  105.     gBufferOffset[newIndex]=gBufferOffset[oldIndex];
  106.     gTheOffset[newIndex][0]=gTheOffset[oldIndex][0];
  107.     gTheOffset[newIndex][1]=gTheOffset[oldIndex][1];
  108.     Mymemcpy(gTheBuffer[newIndex], gTheBuffer[oldIndex], 256);
  109.     gForkLength[newIndex][0]=gForkLength[oldIndex][0];
  110.     gForkLength[newIndex][1]=gForkLength[oldIndex][1];
  111.     gWhichFork[newIndex]=gWhichFork[oldIndex];
  112.     gTheWindow[newIndex+kMainWindow]=gTheWindow[oldIndex+kMainWindow];
  113.     gWindowBounds[newIndex+kMainWindow]=gWindowBounds[oldIndex+kMainWindow];
  114.     Mymemcpy(gWindowTitle[newIndex+kMainWindow], gWindowTitle[oldIndex+kMainWindow],
  115.         256);
  116.     gOffscreenNeedsUpdate[newIndex+kMainWindow]=TRUE;
  117. }
  118.  
  119. void BuildProgramWindowMenu(void)
  120. {
  121.     Str255            theTitle;
  122.     int                i;
  123.     
  124.     if (gWindowMenu!=0L)
  125.     {
  126.         DeleteMenu(windowMenu);
  127.         DisposeMenu(gWindowMenu);
  128.     }
  129.     
  130.     gWindowMenu=NewMenu(windowMenu, "\pWindow");
  131.     
  132.     i=kMainWindow;
  133.     while ((i-kMainWindow<MAX_WINDOWS) && (gTheWindow[i]!=0L))
  134.     {
  135.         GetWTitle(gTheWindow[i], theTitle);
  136.         AppendMenu(gWindowMenu, theTitle);
  137.         i++;
  138.     }
  139.     if (i>kMainWindow)
  140.         InsertMenu(gWindowMenu, 0);
  141.     else
  142.     {
  143.         DisposeMenu(gWindowMenu);
  144.         gWindowMenu=0L;
  145.     }
  146.     
  147.     AdjustMenus();
  148.     DrawMenuBar();
  149. }
  150.